from django.shortcuts import HttpResponse
import requests

# Create your views here.
# 通过接口得到数据
def api_v1(request):
    q = request.GET.get('q')
    print(q)
    params = {
        'q': q,
        't': 'all',
        'p': '1',
        's': '0',
        'tm': '0',
        'lv': '-1',
        'ft': '0',
        'l': '',
        'u': '',
        'ct': '-1',
        'pnt': '-1',
        'ry': '-1',
        'ss': '-1',
        'dct': '-1',
        'vco': '-1',
        'cc': '-1',
        'sc': '-1',
        'akt': '-1',
        'art': '-1',
        'ca': '-1',
        'prs': '',
        'pre': '',
        'ecc': '-1',
        'ebc': '-1',
        'urw': '',
        'ia': '1',
        'dId': '',
        'cl': '-1',
        'scl': '-1',
        'tcl': '-1',
        'platform': 'pc',
        'ab_test_code_overlap': '',
        'ab_test_random_code': '',
    }
    response = requests.get('https://so.csdn.net/api/v3/search', params=params)
    # print(response.text)
    return HttpResponse(response.text)





def api_v2(request):
    category = request.GET.get('category')
    cookies = {
        'uuid_tt_dd': '10_19730457420-1736826227371-941133',
        'fid': '20_38598685936-1736826227297-024157',
        'historyList-new': '%5B%5D',
        'UN': '2401_84436190',
        'p_uid': 'U010000',
        'c_ins_prid': '-',
        'c_ins_rid': '1738575720445_432525',
        'c_ins_fref': 'https://www.csdn.net/',
        'c_ins_fpage': '/index.html',
        'c_ins_um': '-',
        'ins_first_time': '1738575708890',
        'FCNEC': '%5B%5B%22AKsRol9fAilc8FgWjONhouFEw4ZIAmECo9RwirlWIbWS3pdtM9vfcQ3OsDQveezmQ4vaUMtjuKNFoFAVDfNXl3hari0Fj2UJdLULhcze_sU_qHvEUKr6a6k3G4KwDiyCpvjD7-XZomAYCFB1PzaSs5IFVNXbufgEWw%3D%3D%22%5D%5D',
        'FCCDCF': '%5Bnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B13%2C%22%5B%5C%22DBABL~BVQqAAAAAg%5C%22%2C%5B%5B7%2C%5B1740207839%2C230687000%5D%5D%5D%5D%22%5D%5D%5D',
        'ssxmod_itna': 'QqAhqUx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5Fu1QBcSNMbHSQ-DtmoVxdXLSQ4ZqrdPPCLJN6rKjnXen6YRS7mGitW5uejm_RCP31sHf34YCUbFJaLG-5oD9GpDzn8n3mWHxB1lv3rrtp_FBZS1sxm2CGIJoQT33mTvYgLPz1DbF9-w3sT5D7i6_tW5VaKujb9G8Txh40gEzCi-cpyAYqgX7p9HwmEFUG2stWJTKJ0zhFJBCQe3KqZ67p9U8J2nzGTwddAR.',
        'csdn_newcert_2401_84436190': '1',
        'loginbox_strategy': '%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1745132038931%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%222401_84436190%22%2C%22blog-threeH-dialog-expa%22%3A1743050689962%7D',
        'UserName': '2401_84436190',
        'UserInfo': '58a803a51dff427dabc7ba93bbaae80f',
        'UserToken': '58a803a51dff427dabc7ba93bbaae80f',
        'UserNick': '2401_84436190',
        'AU': '408',
        'BT': '1745133357835',
        'c_ab_test': '1',
        '__gads': 'ID=b02f68c827bcc4d8:T=1736826270:RT=1746612139:S=ALNI_Mb5-BytqcsHoyA3jfxnw0FkkTpiKQ',
        '__gpi': 'UID=00000fcdf33ba86f:T=1736826270:RT=1746612139:S=ALNI_MZ5MHzZ2sNi7jZLUEvmXtwC62tqqg',
        '__eoi': 'ID=4e7572574c8f65fe:T=1736826270:RT=1746612139:S=AA-AfjZYfWlnc_BgQdy4iEIu1vEV',
        '_clck': '19qa9in%7C2%7Cfvr%7C0%7C1840',
        'c_first_ref': 'default',
        'c_segment': '13',
        'dc_sid': '4da67242783605ba5dace3dc72e7c8a0',
        'c_utm_source': 'cknow_so_nontop_query',
        'Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac': '1746595570,1746754763,1746836521,1746845882',
        'HMACCOUNT': 'BB6FD7A3A1F38641',
        'c_dl_prid': '1746075244223_881010',
        'c_dl_rid': '1746855623229_676229',
        'c_dl_fref': 'https://www.csdn.net/',
        'c_dl_fpage': '/',
        'c_dl_um': '-',
        'dc_session_id': '10_1746861720167.461860',
        'utm_source': 'cknow_so_nontop_query',
        'c-sidebar-collapse': '0',
        'c_page_id': 'default',
        'c_first_page': 'https%3A//www.csdn.net/',
        'creativeSetApiNew': '%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20231011044944.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A0%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Atrue%2C%22oldFullVersion%22%3Afalse%2C%22userName%22%3A%222401_84436190%22%7D',
        'c_dsid': '11_1746863365638.279500',
        'c_utm_medium': 'distribute.pc_search_hot_word.none-task-hot_word-alirecmd-1-java-null-null.172%5Ev8%5Etag_flag',
        'fe_request_id': '1746863368795_0129_3647191',
        'c_pref': 'https%3A//www.csdn.net/',
        'c_ref': 'https%3A//so.csdn.net/so/search%3Fspm%3D1000.2115.3001.7499%26q%3Djava%26t%3D%26u%3D%26utm_medium%3Ddistribute.pc_search_hot_word.none-task-hot_word-alirecmd-1-java-null-null.172%255Ev8%255Etag_flag%26depth_1-utm_source%3Ddistribute.pc_search_hot_word.none-task-hot_word-alirecmd-1-java-null-null.172%255Ev8%255Etag_flag',
        'Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac': '1746863369',
        'log_Id_pv': '8',
        'log_Id_view': '358',
        'log_Id_click': '10',
        'dc_tos': 'sw1cei',
    }

    headers = {
        'accept': 'application/json, text/plain, */*',
        'accept-language': 'zh-CN,zh;q=0.9',
        'origin': 'https://www.csdn.net',
        'priority': 'u=1, i',
        'referer': 'https://www.csdn.net/',
        'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-site',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
        # 'cookie': 'uuid_tt_dd=10_19730457420-1736826227371-941133; fid=20_38598685936-1736826227297-024157; historyList-new=%5B%5D; UN=2401_84436190; p_uid=U010000; c_ins_prid=-; c_ins_rid=1738575720445_432525; c_ins_fref=https://www.csdn.net/; c_ins_fpage=/index.html; c_ins_um=-; ins_first_time=1738575708890; FCNEC=%5B%5B%22AKsRol9fAilc8FgWjONhouFEw4ZIAmECo9RwirlWIbWS3pdtM9vfcQ3OsDQveezmQ4vaUMtjuKNFoFAVDfNXl3hari0Fj2UJdLULhcze_sU_qHvEUKr6a6k3G4KwDiyCpvjD7-XZomAYCFB1PzaSs5IFVNXbufgEWw%3D%3D%22%5D%5D; FCCDCF=%5Bnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B13%2C%22%5B%5C%22DBABL~BVQqAAAAAg%5C%22%2C%5B%5B7%2C%5B1740207839%2C230687000%5D%5D%5D%5D%22%5D%5D%5D; ssxmod_itna=QqAhqUxmxRxjxWqqBPxeun+YD7YUxYiKdAQ0QD/3vDnqD=GFDK40EE74DCBIWBWDhwteEetYqmxtbEuxhaCj0oP4eSbcodxPTi4B3DEx06x1V=xiicDCeDIDWeDiDG4GmKqGtDpxG=DjY5zlc51DYPDEYYDRPKDu1A+DGczR29+DeKD0Zb7DQIwc2xDB2hEzBi8tAYDeP9+MgOzq0fPFY5D9gYDsx2UCYvIlSd5xR369+73jx0kQq0OZaozz4Gdc=AsYSqW3i0eZAGtTD23q7htQn2bskxqienKqe+NFe+TI+iN7nTVDDcWBHKeD; ssxmod_itna2=QqAhqUxmxRxjxWqqBPxeun+YD7YUxYiKdAQiG9ihBKDBT2q7P5tKg=5eKHdg7OlBYqRNHD82HwGUK82hjH5olqDtRf9WIpheiSwd6XQUEByDz/t8/Pcwi1BR1reUKYM72BuPsVBZBQMX/0q0z3e5g0LYYjqNf+uNYaQN2WTN3vW0oZwt5vbQ/4eNs9q2Y2uQTHdWOKRnH1x3a1gKQERidQdjBiGY2U2+b12y+hhw+QdIj3+cHl10BUhcSU+cBjzBjPuy7MFQA+6Ahd39MKI38XTZ68ZUStHKXb+xylOGffrYlUOVcDudqoo23oldr4W7exo/g32haqWQNnHtWiTChd3rNe3=8iaft1eTG4WWlrrW=Ihw2D3VhDowq=DKERYTqTikbFMIvf5HRbLetZD8=l7KQi/ohxfOS3r37pojr3YkK8oo2QcOfFiTOdFQpWbczqTxfrEx3kz4v3WxK1b8GW2bE5EhADDw2xHDGcDG7CiDD===; tfstk=gEjivrwU8N8spE1-66-_ydgPDHUK6AtXIsnvMnd48BRI6fnO3IAVN6L2kROAtivfRVJZ7IuETKdQCKdAWI2cwBsAWIU_m-X2OdowQI-eYL9rgsXbCKRVgsAAWyERCOtX07n02uBs3etUlGxqM9-6HtckDtrRCOMeekzIYuhc4wjc_I527eWeBBoq0so2YJv2HfuqbsWUKB9DgK8w_9lenK-2gs-4K9RB3AeY7CsVYMPeMrLEDTlRXdYMaORNBOIU5Fu1QBcSNMbHSQ-DtmoVxdXLSQ4ZqrdPPCLJN6rKjnXen6YRS7mGitW5uejm_RCP31sHf34YCUbFJaLG-5oD9GpDzn8n3mWHxB1lv3rrtp_FBZS1sxm2CGIJoQT33mTvYgLPz1DbF9-w3sT5D7i6_tW5VaKujb9G8Txh40gEzCi-cpyAYqgX7p9HwmEFUG2stWJTKJ0zhFJBCQe3KqZ67p9U8J2nzGTwddAR.; csdn_newcert_2401_84436190=1; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1745132038931%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%222401_84436190%22%2C%22blog-threeH-dialog-expa%22%3A1743050689962%7D; UserName=2401_84436190; UserInfo=58a803a51dff427dabc7ba93bbaae80f; UserToken=58a803a51dff427dabc7ba93bbaae80f; UserNick=2401_84436190; AU=408; BT=1745133357835; c_ab_test=1; __gads=ID=b02f68c827bcc4d8:T=1736826270:RT=1746612139:S=ALNI_Mb5-BytqcsHoyA3jfxnw0FkkTpiKQ; __gpi=UID=00000fcdf33ba86f:T=1736826270:RT=1746612139:S=ALNI_MZ5MHzZ2sNi7jZLUEvmXtwC62tqqg; __eoi=ID=4e7572574c8f65fe:T=1736826270:RT=1746612139:S=AA-AfjZYfWlnc_BgQdy4iEIu1vEV; _clck=19qa9in%7C2%7Cfvr%7C0%7C1840; c_first_ref=default; c_segment=13; dc_sid=4da67242783605ba5dace3dc72e7c8a0; c_utm_source=cknow_so_nontop_query; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1746595570,1746754763,1746836521,1746845882; HMACCOUNT=BB6FD7A3A1F38641; c_dl_prid=1746075244223_881010; c_dl_rid=1746855623229_676229; c_dl_fref=https://www.csdn.net/; c_dl_fpage=/; c_dl_um=-; dc_session_id=10_1746861720167.461860; utm_source=cknow_so_nontop_query; c-sidebar-collapse=0; c_page_id=default; c_first_page=https%3A//www.csdn.net/; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20231011044944.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A0%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Atrue%2C%22oldFullVersion%22%3Afalse%2C%22userName%22%3A%222401_84436190%22%7D; c_dsid=11_1746863365638.279500; c_utm_medium=distribute.pc_search_hot_word.none-task-hot_word-alirecmd-1-java-null-null.172%5Ev8%5Etag_flag; fe_request_id=1746863368795_0129_3647191; c_pref=https%3A//www.csdn.net/; c_ref=https%3A//so.csdn.net/so/search%3Fspm%3D1000.2115.3001.7499%26q%3Djava%26t%3D%26u%3D%26utm_medium%3Ddistribute.pc_search_hot_word.none-task-hot_word-alirecmd-1-java-null-null.172%255Ev8%255Etag_flag%26depth_1-utm_source%3Ddistribute.pc_search_hot_word.none-task-hot_word-alirecmd-1-java-null-null.172%255Ev8%255Etag_flag; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1746863369; log_Id_pv=8; log_Id_view=358; log_Id_click=10; dc_tos=sw1cei',
    }

    params = {
        'componentIds': 'silkroad-pre-home-list',
        'cate1': category,
    }

    response = requests.get('https://cms-api.csdn.net/v1/web_home/select_content', params=params, cookies=cookies,
                            headers=headers)
    return HttpResponse(response.text)
